home *** CD-ROM | disk | FTP | other *** search
- Path: ix.netcom.com!netnews
- From: miker3@ix.netcom.com (Mike Rubenstein)
- Newsgroups: comp.lang.c++
- Subject: Re: Overloading conversion
- Date: Sun, 14 Jan 1996 17:05:03 GMT
- Organization: Netcom
- Message-ID: <30f93747.165768512@nntp.ix.netcom.com>
- References: <4d934v$10hs@ds2.acs.ucalgary.ca> <ENNO.96Jan14111826@kitz.inferenzsysteme.informatik.th-darmstadt.de>
- NNTP-Posting-Host: ix-dc18-06.ix.netcom.com
- X-NETCOM-Date: Sun Jan 14 9:04:23 AM PST 1996
- X-Newsreader: Forte Agent .99c/16.141
-
- enno@inferenzsysteme.informatik.th-darmstadt.de (Enno Sandner) wrote:
-
- |>In article <4d934v$10hs@ds2.acs.ucalgary.ca>
- hdang@acs3.acs.ucalgary.ca (Hanna Dang) writes:
- |>
- |> Is there a way to overload functions such that certain
- |> functions are called depending on the context the object are
- |> used. For example,
- |>
- |> class T {
- |> public:
- |> int& int_value() { modified = TRUE; return value;}
- |> int int_value() {return value;}
- |> private:
- |> int value;
- |> int modified;
- |> }
- |>
- |>
- |> ...
- |>
- |> T a;
- |> int test = a + 6 // int int_value should be called;
- |> a = 20 // int& int_value should be called.
- |>
- |> However, this does not work because in both case int& int_value
- |> is called. Is there another way to find out if value is changed
- |> or it's just inspected.
- |>
- |>Yes -- make the latter 'int_value' a const member-function, ie.
- |>
- |> int int_value() const {return value;}
-
- Have you tried this? If so, what compiler? I want to make sure I
- avoid it.
-
- The decision as to whether to call the const or non-const version of a
- member function is based on whether the class object is const, not on
- which side of the equal sign it appears. In both cases above, the
- non-const version will be called since a is not const.
-
-
- Michael M Rubenstein
-